package com.systemsetup.systemsetup.web.web;

import cn.hutool.json.JSONObject;
import com.systemsetup.systemsetup.common.utils.Dict;
import com.systemsetup.systemsetup.support.annotaion.Action;
import com.systemsetup.systemsetup.support.annotaion.At;
import com.systemsetup.systemsetup.support.model.RespEntity;
import com.systemsetup.systemsetup.web.service.SystemsetupService;
import com.systemsetup.systemsetup.web.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.Map;


@Action
@RequestMapping(value = "systemsetup")
public class SystemsetupController {
    @Resource
    public SystemsetupService systemsetupService;
    @Resource
    public UserService userService;

    /**
     * 用户详情
     *
     * @param
     * @return
     */
    @At(value = "userDetail", method = RequestMethod.GET)
    public RespEntity userDetail(@RequestBody(required = false) JSONObject jsonParam) throws Exception {

        return systemsetupService.userDetail(jsonParam);
    }

    /**
     * 用户修改
     *
     * @param
     * @return
     */
    @At(value = "userUpdate", method = RequestMethod.POST)
    public RespEntity userUpdate(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return systemsetupService.userUpdate(jsonParam);
    }

    /**
     * 用户增加
     *
     * @param
     * @return
     */
    @At(value = "userAdd", method = RequestMethod.POST)
    public RespEntity userAdd(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return systemsetupService.userAdd(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 创建舆情平台子帐号并绑定
     * @Date Created in 14:20 2023/4/19
     * @Param [jsonParam]
     */
    @At(value = "accountContactCreateSub", method = RequestMethod.POST, param = {"id"})
    public RespEntity accountContactCreateSub(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.accountContactCreateSub(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 免鉴权平台 用户验证并登录
     * @Date Created in 14:20 2023/4/19
     * @Param [jsonParam]
     */
    @At(value = "accountContactCheck", method = RequestMethod.POST)
    public RespEntity accountContactCheck(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.accountContactCheck(jsonParam);
    }

    /**
     * 账号删除
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/userDelete", method = RequestMethod.POST)
    public RespEntity userDelete(@RequestBody(required = false) JSONObject jsonParam) {
        return userService.userDelete(jsonParam);
    }

    /**
     * 单位删除时调用接口
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "userCount", method = RequestMethod.POST)
    public int userCount(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return systemsetupService.userCount(jsonParam);
    }

    /**
     * 权限列表
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/permissionsTreeList", method = RequestMethod.GET)
    public RespEntity permissionsTreeList(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.permissionsTreeList(jsonParam);
    }

    /**
     * 用户列表
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/userListPage", method = RequestMethod.GET)
    public RespEntity userListPage(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.userListPage(jsonParam);
    }

    /**
     * 单位获取账号列表
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getUserList", method = RequestMethod.GET)
    public RespEntity getUserList(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getUserList(jsonParam);
    }

    /**
     * 设备导出的时候调用
     *
     * @param map
     * @return
     */
    @At(path = "userInfo", method = RequestMethod.GET)
    public RespEntity userInfo(@RequestParam Map<String, Object> map) {
        return systemsetupService.userInfo(map);
    }

    /**
     * @param jsonParam
     * @return
     * @Title: getNewestVersionUpdate <br>
     * @Description: (获取最新版本) <br>
     * @author 石延杰<br>
     */
    @At(path = "getNewestVersionUpdate", method = RequestMethod.GET)
    public RespEntity getNewestVersionUpdate(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getNewestVersionUpdate(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 世成电器版本号
     * @Date Created in 9:43 2022/8/16
     * @Param [jsonParam]
     */

    @At(path = "getAppVersionScList", method = RequestMethod.GET)
    public JSONObject getAppVersionScList(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getAppVersionScList(jsonParam);
    }

    /**
     * 设置文字标题
     *
     * @param jsonParam
     * @return
     */
    @At(value = "setTextTitle", method = RequestMethod.POST)
    public RespEntity setTextTitle(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.setTextTitle(jsonParam);
    }

    /**
     * 获取文字标题
     *
     * @param jsonParam
     * @return
     */
    @At(value = "getTextTitle", method = RequestMethod.GET)
    public RespEntity getTextTitle(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.getTextTitle(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 获取首页布局信息
     * @Date Created in 9:41 2022/5/7
     * @Param [jsonParam]
     */
    @At(value = "getHomePageLayoutList", method = RequestMethod.GET, param = {"homeId"})
    public RespEntity getHomePageLayoutList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.getHomePageLayoutList(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 设置首页布局信息
     * @Date Created in 9:41 2022/5/7
     * @Param [jsonParam]
     */
    //@At(value = "setHomePageLayoutList", method = RequestMethod.POST )
    @RequestMapping(value = "setHomePageLayoutList", method = RequestMethod.POST)
    public RespEntity setHomePageLayoutList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.setHomePageLayoutList(jsonParam);
    }

    /**
     * 账户密码修改
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updatePassWord", method = RequestMethod.POST)
    public RespEntity updatePassWord(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return systemsetupService.updatePassWord(jsonParam);
    }

    /**
     * 用户登录
     *
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public RespEntity login(@RequestParam Map<String, Object> map) throws Exception {
        return userService.login(Dict.create(map));
    }

    /**
     * @Author YangYu
     * @Description 用户注册
     * @Date Created in 11:06 2024/5/8
     * @Param [jsonParam]
     */

    @At(value = "/register", method = RequestMethod.POST, param = {"phone", "code", "type"})
    public RespEntity register(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return userService.register(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 更新用户绑定单位
     * @Date Created in 11:06 2024/5/8
     * @Param [jsonParam]
     */

    @At(value = "/updateUserHomeId", method = RequestMethod.POST, param = {"userId", "businessId"})
    public RespEntity updateUserHomeId(@RequestBody(required = false) JSONObject jsonParam) {
        return userService.updateUserHomeId(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 获取验证码（找回密码用）
     * @Date Created in 11:06 2024/5/8
     * @Param [jsonParam]
     */

    @At(value = "/getVerificationCode", method = RequestMethod.POST, param = {"phone"})
    public RespEntity getVerificationCode(@RequestBody(required = false) JSONObject jsonParam) {
        return userService.getVerificationCode(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 身份验证（找回密码用）
     * @Date Created in 11:06 2024/5/8
     * @Param [jsonParam]
     */

    @At(value = "/identityVerification", method = RequestMethod.POST, param = {"phone"})
    public RespEntity identityVerification(@RequestBody(required = false) JSONObject jsonParam) throws ParseException {
        return userService.identityVerification(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 密码重置（忘记密码用）
     * @Date Created in 11:06 2024/5/8
     * @Param [jsonParam]
     */

    @At(value = "/passwordReset", method = RequestMethod.POST, param = {"phone", "password"})
    public RespEntity passwordReset(@RequestBody(required = false) JSONObject jsonParam) throws ParseException {
        return userService.passwordReset(jsonParam);
    }

    /**
     * 用户退出短token
     *
     * @param map
     * @param httpServletRequest
     * @param response
     * @return
     */
    @RequestMapping(value = "/logout", method = RequestMethod.DELETE)
    public RespEntity logout(@RequestParam Map<String, Object> map, HttpServletRequest httpServletRequest, HttpServletResponse response) {
        return userService.logout(Dict.create(map), httpServletRequest, response);
    }

    /**
     * 用户退出长token
     *
     * @param jsonParam
     * @param httpServletRequest
     * @param response
     * @return
     */
    @RequestMapping(value = "/logout2", method = RequestMethod.DELETE)
    public RespEntity logout2(@RequestBody(required = false) JSONObject jsonParam, HttpServletRequest httpServletRequest, HttpServletResponse response) {
        return userService.logout2(jsonParam, httpServletRequest, response);
    }

    /**
     * 如果短token过期，重新生存一个token
     *
     * @param map
     * @param httpServletRequest
     * @param response
     * @return
     */
    @RequestMapping(value = "/refresh", method = RequestMethod.POST)
    public RespEntity refresh(@RequestParam Map<String, Object> map, HttpServletRequest httpServletRequest, HttpServletResponse response) {
        return userService.refresh(Dict.create(map), httpServletRequest, response);
    }

    /**
     * 解析token
     *
     * @param map
     * @param httpServletRequest
     * @param response
     * @return
     */
    @RequestMapping(value = "/getDecodeToken", method = RequestMethod.GET)
    public RespEntity getDecodeToken(@RequestParam Map<String, Object> map, HttpServletRequest httpServletRequest, HttpServletResponse response) {
        return userService.getDecodeToken(Dict.create(map), httpServletRequest, response);
    }


    @RequestMapping(value = "/getDecodeTokenNew", method = RequestMethod.POST)
    public RespEntity getDecodeTokenNew(@RequestBody(required = false) JSONObject jsonParam, HttpServletRequest httpServletRequest, HttpServletResponse response) {
        return userService.getDecodeTokenNew(jsonParam, httpServletRequest, response);
    }

    /**
     * 单一机构账户列表
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/userListByOrgId", method = RequestMethod.GET)
    public RespEntity userListByOrgId(@RequestBody(required = false) JSONObject jsonParam) {
        return userService.userListByOrgId(jsonParam);
    }

    /**
     * 账号不分页列表
     *
     * @param jsonParam
     * @param httpServletRequest
     * @return
     */
    @RequestMapping(value = "/userList", method = RequestMethod.GET)
    public RespEntity userList(@RequestBody(required = false) JSONObject jsonParam, HttpServletRequest httpServletRequest) {
        return systemsetupService.userList(jsonParam, httpServletRequest);
    }

    /**
     * 机构和子机构列表
     *
     * @param jsonParam
     * @param httpServletRequest
     * @return
     */
    @RequestMapping(value = "/orgAllList", method = RequestMethod.GET)
    public RespEntity orgAllList(@RequestBody(required = false) JSONObject jsonParam, HttpServletRequest httpServletRequest) {
        return systemsetupService.orgAllList(jsonParam, httpServletRequest);
    }

    /**
     * @Author YangYu
     * @Description 机构和子机构列表(递归查询)
     * @Date Created in 15:09 2023/2/2
     * @Param [jsonParam, httpServletRequest]
     */

    @RequestMapping(value = "/getOrgAllList", method = RequestMethod.GET)
    public RespEntity getOrgAllList(@RequestBody(required = false) JSONObject jsonParam, HttpServletRequest httpServletRequest) {
        return systemsetupService.getOrgAllList(jsonParam, httpServletRequest);
    }

    /**
     * 获取cid
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getCId", method = RequestMethod.GET)
    public RespEntity getCId(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getCId(jsonParam);
    }

    /**
     * 获取所有和设备号相关的cid
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getAllCidFromNumber", method = RequestMethod.GET)
    public RespEntity getAllCidFromNumber(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getAllCidFromNumber(jsonParam);
    }

    /**
     * 获取所有和设备号相关的Openid
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getAllOpenIdFromNumber", method = RequestMethod.GET)
    public RespEntity getAllOpenIdFromNumber(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getAllOpenIdFromNumber(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 删除openid
     * @Date Created in 13:45 2020/12/14
     * @Param [jsonParam]
     */
    @RequestMapping(value = "/delOpenId", method = RequestMethod.GET)
    public RespEntity delOpenId(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.delOpenId(jsonParam);
    }

    @RequestMapping(value = "/getOrgNameByOrgName", method = RequestMethod.GET)
    public RespEntity getOrgNameByOrgName(@RequestBody(required = false) JSONObject jsonParam) {
        return systemsetupService.getOrgNameByOrgName(jsonParam);
    }

    /**
     * 角色新增
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleAdd", method = RequestMethod.POST)
    public RespEntity roleAdd(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleAdd(jsonParam);
    }

    /**
     * 角色删除
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleDelete", method = RequestMethod.POST)
    public RespEntity roleDelete(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleDelete(jsonParam);
    }

    /**
     * 角色编辑
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleUpdate", method = RequestMethod.POST)
    public RespEntity roleUpdate(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleUpdate(jsonParam);
    }

    /**
     * 角色详情
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleDetail", method = RequestMethod.GET)
    public RespEntity roleDetail(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleDetail(jsonParam);
    }

    /**
     * 角色表分页查询
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleListPage", method = RequestMethod.GET, params = {"page", "limit"})
    public RespEntity roleListPage(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleListPage(jsonParam);
    }

    /**
     * 角色不分页列表
     *
     * @param jsonParam
     * @return YangYu
     */
    @RequestMapping(value = "/roleListNoPage", method = RequestMethod.GET)
    public RespEntity roleListNoPage(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleListNoPage(jsonParam);
    }

    /**
     * 角色表不分页列表
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/roleList", method = RequestMethod.GET)
    public RespEntity roleList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.roleList(jsonParam);
    }

    /**
     * 角色和权限关联后的权限列表不分页
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/rolePermissionsList", method = RequestMethod.GET)
    public RespEntity rolePermissionsList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.rolePermissionsList(jsonParam);
    }


    /**
     * 用户设置角色回显
     *
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/userSetRoleEcho", method = RequestMethod.POST)
    public RespEntity userSetRoleEcho(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.userSetRoleEcho(jsonParam);
    }


    /**
     * 获取标题图片
     *
     * @param jsonParam
     * @return
     */
    @At(value = "getHeaderTitle", method = RequestMethod.GET)
    public RespEntity getHeaderTitle(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.getHeaderTitle(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 授权
     * @Date Created in 14:25 2023/2/3
     * @Param [jsonParam]
     */

    @RequestMapping(value = "/authorization", method = RequestMethod.POST)
    public RespEntity authorization(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.authorization(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 取消授权
     * @Date Created in 14:25 2023/2/3
     * @Param [jsonParam]
     */

    @RequestMapping(value = "/cancelAuthorization", method = RequestMethod.POST)
    public RespEntity cancelAuthorization(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.cancelAuthorization(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 设置处置弹框
     * @Date Created in 13:47 2023/2/21
     * @Param [jsonParam]
     */

    @At(value = "setFrameMonitoring", method = RequestMethod.POST, param = {"state", "time"})
    public RespEntity setFrameMonitoring(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.setFrameMonitoring(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 设置处置弹框详情
     * @Date Created in 13:47 2023/2/21
     * @Param [jsonParam]
     */
    @RequestMapping(value = "/frameMonitoringDetails", method = RequestMethod.GET)
    public RespEntity setFrameMonitoringDetails(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.setFrameMonitoringDetails(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 大屏设置
     * @Date Created in 13:47 2023/2/21
     * @Param [jsonParam]
     */

    @At(value = "largeScreenSettings", method = RequestMethod.POST, param = {"fileUrl", "type"})
    public RespEntity largeScreenSettings(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.largeScreenSettings(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 大屏设置列表
     * @Date Created in 13:47 2023/2/21
     * @Param [jsonParam]
     */
    @RequestMapping(value = "/largeScreenList", method = RequestMethod.GET)
    public RespEntity largeScreenList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.largeScreenList(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 大屏设置删除
     * @Date Created in 13:47 2023/2/21
     * @Param [jsonParam]
     */
    @At(value = "largeScreenDel", method = RequestMethod.POST, param = {"type"})
    public RespEntity largeScreenDel(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.largeScreenDel(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 置顶应用新增
     * @Date Created in 14:19 2024/5/11
     * @Param [jsonParam]
     */

    @At(value = "topAppAdd", method = RequestMethod.POST, param = {"moduleId"})
    public RespEntity topAppAdd(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.topAppAdd(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 置顶应用删除
     * @Date Created in 14:19 2024/5/11
     * @Param [jsonParam]
     */

    @At(value = "topAppDel", method = RequestMethod.POST, param = {"moduleId"})
    public RespEntity topAppDel(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.topAppDel(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 置顶应用列表
     * @Date Created in 14:19 2024/5/11
     * @Param [jsonParam]
     */

    @At(value = "topAppList", method = RequestMethod.GET)
    public RespEntity topAppList(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.topAppList(jsonParam);
    }


    /**
     * @Author YangYu
     * @Description 更新记录新增、编辑
     * @Date Created in 10:08 2024/5/21
     * @Param [jsonParam]
     */

    @At(value = "renewInfoAddOrUpdate", method = RequestMethod.POST)
    public RespEntity renewInfoAddOrUpdate(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.renewInfoAddOrUpdate(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 更新记录分页列表
     * @Date Created in 10:14 2024/5/21
     * @Param [jsonParam]
     */

    @At(value = "renewInfoListPage", method = RequestMethod.GET,param = {"page","limit"})
    public RespEntity renewInfoListPage(@RequestBody(required = false) JSONObject jsonParam) {
        return this.systemsetupService.renewInfoListPage(jsonParam);
    }

}
